package org.springblade.modules.platform.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springblade.core.tool.utils.BeanUtil;
import org.springblade.core.tool.utils.Func;
import org.springblade.modules.platform.entity.MeasuringChainPlatformInfo;
import org.springblade.modules.platform.entity.MeasuringChainPlatformInfov1;
import org.springblade.modules.platform.mapper.MeasuringChainPlatformInfoV1Mapper;
import org.springblade.modules.platform.service.IMeasuringChainPlatformInfoV1Service;


import org.springframework.stereotype.Service;

;import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author SYG
 * @since 2023-07-10
 */
@Service
public class MeasuringChainPlatformInfoV1ServiceImpl extends ServiceImpl<MeasuringChainPlatformInfoV1Mapper, MeasuringChainPlatformInfov1> implements IMeasuringChainPlatformInfoV1Service {

	@Override
	public List<MeasuringChainPlatformInfo> getMeasuringChainPlatformInfo(Long measuringTypeId) {
		List<MeasuringChainPlatformInfov1> measuringChainPlatformInfos = baseMapper.selectList(Wrappers.<MeasuringChainPlatformInfov1>query().lambda().eq(MeasuringChainPlatformInfov1::getMeasuringTypeId, measuringTypeId));
		if(Func.isEmpty(measuringChainPlatformInfos)){
			return null;
		}
		List<MeasuringChainPlatformInfo> collect = measuringChainPlatformInfos.stream().map(x -> BeanUtil.copy(x, MeasuringChainPlatformInfo.class)).collect(Collectors.toList());
		return collect.stream().sorted(Comparator.comparing(MeasuringChainPlatformInfo::getSort)).collect(Collectors.toList());
	}
}
